/**
*
* 2007-11-5 下午05:46:28
* @author xuhuan
*/

package edu.ccut.saturn.studio.logic.model.xml.loader;

import java.util.ArrayList;
import java.util.List;

import org.eclipse.draw2d.geometry.Dimension;
import org.eclipse.draw2d.geometry.Point;
import org.w3c.dom.Element;
import org.w3c.dom.Node;
import org.w3c.dom.NodeList;

import edu.ccut.saturn.studio.logic.model.Shape;
import edu.ccut.saturn.studio.logic.model.saturn.SaturnTransactionCommitNode;

public class TransactionCommitLoader extends NodeLoader {

	@Override
	public List<Shape> loadNodes(Element root) {
		
		NodeList transactionCommitNodes = root.getElementsByTagName(SaturnTransactionCommitNode.KEY_NODE_TRANSATIONCOMMIT);
		
		List<Shape> shapes = new ArrayList<Shape>(transactionCommitNodes.getLength());
		
		for (int i = 0; i < transactionCommitNodes.getLength(); ++i) {
			SaturnTransactionCommitNode transactionCommitNode = new SaturnTransactionCommitNode();
			Node startNode = transactionCommitNodes.item(i);
			String shapeId = super.getNodeAttributeValue(startNode, Shape.KEY_ATTRIBUTE_SHAPE_ID);
			String nextId = super.getNodeAttributeValue(startNode, Shape.KEY_ATTRIBUTE_SHAPE_NEXT_ID);
			String name = super.getNodeElementValue(startNode, SaturnTransactionCommitNode.SHOW_NODE_TRANSATIONCOMMIT_NAME);
			String description = super.getNodeElementValue(startNode, SaturnTransactionCommitNode.SHOW_NODE_TRANSATIONCOMMIT_DESCRIPTION);
			
			Point location = super.getLocation(startNode);
			Dimension size = new Dimension(50, 70);
			
			transactionCommitNode.setNode(startNode);
			transactionCommitNode.setId(shapeId);
			transactionCommitNode.setLocation(location);
			transactionCommitNode.setName(name);
			transactionCommitNode.setNextId(nextId);
			transactionCommitNode.setDescription(description);
			transactionCommitNode.setSize(size);
			
			shapes.add(transactionCommitNode);
		}
		
		return shapes;
	}

}
